<?php

namespace App\Admin\Controllers;

use App\Models\Region;
use App\Models\Selectedline;
use App\Http\Controllers\Controller;
use App\Models\Selectedmenu;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class SelectedlineController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('精品路线管理')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('编辑精品路线')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('新增精品路线')
            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Selectedline);

        $grid->id('ID');
        $grid->type()->badge();
        $grid->coverimage()->image('http://media.weijingguanjia.com/',36,36);
        $grid->columns('title','tag','area','iphone','price','carfare','author','watch','attention');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Selectedline::findOrFail($id));

        $show->id('ID');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Selectedline);

        $form->select('type','所属菜单')->options(Selectedmenu::all()->pluck('text', 'id'));
        $form->text('title', '标题')->rules('required');
        $form->ueditor('content', '内容')->rules('required');
        $form->image('coverimage','封面图片')->uniqueName()->removable()->rules('required');
        $form->text('author', '编辑');
        $form->tags('tag', '标签')->rules('required');
        $form->select('area', '区域')->options(Region::all()->pluck('text', 'text'));
        $form->text('iphone', '电话');
        $form->text('attention', '注意事项');
        $form->number('price','门票');
        $form->number('carfare','交通费');

        return $form;
    }
}
